module.exports = class {
  constructor(model, obj) {
    this.model = model;
    Reflect.ownKeys(Reflect.getPrototypeOf(obj)).filter(el => {
      if (typeof el === 'string') {
        return el !== '__filename' && el !== 'constructor' && !el.startsWith('_');
      }
      return false;
    }).forEach(key => {
      this[key] = this.__call.bind(this, key);
    });
  }
  __call(func) {
    try {
      const obj = think.model(this.model, {}, 'home');
      return obj[func].apply(obj, Array.prototype.splice.call(arguments, 1));
    } catch (e) {
      if (!e.isCustom) {
        think.logger.error(e);
      }
      throw e;
    }
  }
};
